/*                                  ATELIER                                   */

/* %%LICENSE_TAG%%                                                            */
package edu.gmu.view.canvas;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Shape;
import javax.swing.JComponent;

/*******************************************************************
 * Fills an area of the JComponent with a Color.
 * <p>
 * Useful for setting the background Color of a Component.  Note that
 * if you are also using an opaque (non-transparent) background Image,
 * using a background Color could be a waste of CPU cycles if it is
 * completely covered by the background Image.
 * <p>
 * Semi-transparent Colors may be useful for darkening or color
 * tinting a scene.
 *******************************************************************/
public final class BackgroundLayer extends AbstractLayer
{
    private static final long  serialVersionUID = 0L;
    //
    private Color  color;
    private Shape  shape;
    
    /**
     * Creates a new BackgroundLayer with default paramters.
     */
    public BackgroundLayer ( )
    {
        
    }
    
    /**
     * Creates a new BackgroundLayer with specified paramters.
     * 
     * 
     * 
     * @param color
     */
    public BackgroundLayer ( Color  color )
    {
        this.color = color;
    }
    
    /**
     * Creates a new BackgroundLayer with specified paramters.
     * 
     * 
     * 
     * @param color
     * @param shape
     */
    public BackgroundLayer ( Color  color, Shape  shape )
    {
        this.color = color;
        this.shape = shape;
    }
    

    //////////////////////////////////////////////////////////////////////
    // accessor methods
    //////////////////////////////////////////////////////////////////////

    /**
     *
     * @return
     */
    public Color getColor( )
    {
        return color;
    }

    /**
     *
     * @return
     */
    public Shape getShape( )
    {
        return shape;
    }

    //////////////////////////////////////////////////////////////////////
    // mutator methods
    //////////////////////////////////////////////////////////////////////

    /**
     *
     * @param color
     */
    public void setColor( Color  color )
    {
        this.color = color;
    }

    /**
     *
     * @param shape
     */
    public void setShape( Shape  shape )
    {
        this.shape = shape;
    }
    
    /*********************************************************************
     * Updates position of components located within component.
     *
     * @param component
     ********************************************************************/
    public void updateLayer( JComponent component )
    {
        // do nothing
    }
    
    /*********************************************************************
     * Paints images on specified Component object using passed Graphics.
     *
     * @param component
     * @param graphics
     *********************************************************************/
    public void paintLayer( JComponent  component, Graphics2D  graphics )
    {
        if ( color == null )
        {
            graphics.setColor ( component.getBackground ( ) );
        }
        else
        {
            graphics.setColor ( color );
        }

        if ( shape == null )
        {   
            /*
             * Effectively a background
             */
            graphics.fillRect ( 0, 0, component.getWidth(), component.getHeight() );
        }
        else
        {
            // graphics.fill(Shape) does not like Integer.MAX_VALUE
            graphics.fill ( shape );
        }
    }
     
}

/*                                  ATELIER                                   */